package com.ruoyi.web.controller.interview;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.interview.domain.IntervPostinv;
import com.ruoyi.interview.service.IIntervPostinvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * BaseController 继承了Controller，Controller是SpringMVC的注解，用于标识这是一个Controller
 * */
@RestController
@RequestMapping("/interview/postinv")
public class IntervPostinvController extends BaseController
{
    /** 注入service */
    @Autowired
    private IIntervPostinvService intervPostinvService;

    /** 查询 */
    // @PreAuthorize("@ss.hasPermi('system:postinv:query')")
    @GetMapping("/list")
    public TableDataInfo list(IntervPostinv intervPostinv)
    {
        /** 分页 */
        startPage();
        List<IntervPostinv> list = intervPostinvService.selectIntervPostinvList(intervPostinv);
        return getDataTable(list);
    }

    /** 导出 */
    @PreAuthorize("@ss.hasPermi('system:postinv:export')")
    @Log(title = "导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IntervPostinv intervPostinv)
    {
        List<IntervPostinv> list = intervPostinvService.selectIntervPostinvList(intervPostinv);
        /** 创建ExcelUtil对象,传入实体类 */
        ExcelUtil<IntervPostinv> util = new ExcelUtil<IntervPostinv>(IntervPostinv.class);
        util.exportExcel(response, list, "面试信息数据数据");
    }

    /** 获取 */
    @PreAuthorize("@ss.hasPermi('system:postinv:query')")
    @GetMapping(value = "/{pId}")
    public AjaxResult getInfo(@PathVariable("pId") Long pId)
    {
        return AjaxResult.success(intervPostinvService.selectIntervPostinvByPId(pId));
    }

    /** 新增 */
    @PreAuthorize("@ss.hasPermi('system:postinv:add')")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IntervPostinv intervPostinv)
    {
        return toAjax(intervPostinvService.insertIntervPostinv(intervPostinv));
    }

    /** 修改 */
    @PreAuthorize("@ss.hasPermi('system:postinv:edit')")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IntervPostinv intervPostinv)
    {
        return toAjax(intervPostinvService.updateIntervPostinv(intervPostinv));
    }

    /**
     * 删除
     * 关于删除为什么用/{pIds}确能传递一个数组
     * 因为转换器，把前端传过来的对象以 ， 进行分割
     */
    @PreAuthorize("@ss.hasPermi('system:postinv:remove')")
    @Log(title = "删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pIds}")
    public AjaxResult remove(@PathVariable Long[] pIds)
    {
        return toAjax(intervPostinvService.deleteIntervPostinvByPIds(pIds));
    }
}
